package com.data.modules.online.cgform.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import com.data.common.api.vo.Result;
import com.data.common.system.base.controller.BootController;
import com.data.common.system.query.QueryGenerator;
import com.data.modules.online.cgform.entity.OnlCgformField;
import com.data.modules.online.cgform.service.IOnlCgformFieldService;
import com.data.modules.online.cgform.service.IOnlCgformHeadService;
import com.data.modules.online.cgform.util.CgformUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "onlCgformFieldController")
@RequestMapping("/online/cgform/field")
@RestController
public class OnlCgformFieldController {

    private static final Logger f98a = LoggerFactory.getLogger(OnlCgformFieldController.class);
    @Autowired
    private IOnlCgformFieldService onlCgformFieldService;
    @Autowired
    @Lazy(true)
    private IOnlCgformHeadService onlCgformHeadService;

    private static /* synthetic */ java.lang.Object m80a(java.lang.invoke.SerializedLambda r3) {
        /*
        // Method dump skipped, instructions count: 118
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformFieldController.m80a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

@org.springframework.web.bind.annotation.GetMapping({"/listByHeadCode"})
public com.data.common.api.vo.Result<?> mo338a(@org.springframework.web.bind.annotation.RequestParam("headCode") java.lang.String r3) {
        /*
            r2 = this;
            com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper r0 = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
            void r1 = r0.<init>()
            r0.eq(r1, r3)
            org.jeecg.modules.online.cgform.service.IOnlCgformHeadService r1 = r2.onlCgformHeadService
            java.lang.Object r0 = r1.getOne(r0)
            org.jeecg.modules.online.cgform.entity.OnlCgformHead r0 = (org.jeecg.modules.online.cgform.entity.OnlCgformHead) r0
            if (r0 != 0) goto L_0x001d
            java.lang.String r0 = "不存在的code"
            com.data.common.api.vo.Result r0 = com.data.common.api.vo.Result.error(r0)
        L_0x001c:
            return r0
        L_0x001d:
            java.lang.String r0 = r0.getId()
            com.data.common.api.vo.Result r0 = r2.mo341b(r0)
            goto L_0x001c
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformFieldController.mo338a(java.lang.String):com.data.common.api.vo.Result");
    }

    @GetMapping({"/listByHeadId"})
    public Result<?> mo341b(@RequestParam("headId") String str) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("cgform_head_id", str);
        queryWrapper.orderByAsc("order_num");
        return Result.ok(this.onlCgformFieldService.list(queryWrapper));
    }

    @GetMapping({"/list"})
    public Result<IPage<OnlCgformField>> mo340a(OnlCgformField onlCgformField, @RequestParam(defaultValue = "1", name = "pageNo") Integer num, @RequestParam(defaultValue = "10", name = "pageSize") Integer num2, HttpServletRequest httpServletRequest) {
        Result<IPage<OnlCgformField>> result = new Result<>();
        Wrapper initQueryWrapper = QueryGenerator.initQueryWrapper(onlCgformField, httpServletRequest.getParameterMap());
        IPage page = this.onlCgformFieldService.page(new Page((long) num.intValue(), (long) num2.intValue()), initQueryWrapper);
        result.setSuccess(true);
        result.setResult(page);
        return result;
    }

    @PostMapping({"/add"})
    public Result<OnlCgformField> mo339a(@RequestBody OnlCgformField onlCgformField) {
        Result<OnlCgformField> result = new Result<>();
        try {
            this.onlCgformFieldService.save(onlCgformField);
            result.success("添加成功！");
        } catch (Exception e) {
            f98a.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    @PutMapping({"/edit"})
    public Result<OnlCgformField> mo342b(@RequestBody OnlCgformField onlCgformField) {
        Result<OnlCgformField> result = new Result<>();
        if (((OnlCgformField) this.onlCgformFieldService.getById(onlCgformField.getId())) == null) {
            result.error500("未找到对应实体");
        } else if (this.onlCgformFieldService.updateById(onlCgformField)) {
            result.success("修改成功!");
        }
        return result;
    }

    @DeleteMapping({"/delete"})
    public Result<OnlCgformField> mo343c(@RequestParam(name = "id", required = true) String str) {
        Result<OnlCgformField> result = new Result<>();
        if (((OnlCgformField) this.onlCgformFieldService.getById(str)) == null) {
            result.error500("未找到对应实体");
        } else if (this.onlCgformFieldService.removeById(str)) {
            result.success("删除成功!");
        }
        return result;
    }

    @DeleteMapping({"/deleteBatch"})
    public Result<OnlCgformField> mo344d(@RequestParam(name = "ids", required = true) String str) {
        Result<OnlCgformField> result = new Result<>();
        if (str == null || "".equals(str.trim())) {
            result.error500("参数不识别！");
        } else {
            this.onlCgformFieldService.removeByIds(Arrays.asList(str.split(CgformUtil.f231E)));
            result.success("删除成功!");
        }
        return result;
    }

    @GetMapping({"/queryById"})
    public Result<OnlCgformField> mo345e(@RequestParam(name = "id", required = true) String str) {
        Result<OnlCgformField> result = new Result<>();
        OnlCgformField onlCgformField = (OnlCgformField) this.onlCgformFieldService.getById(str);
        if (onlCgformField == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(onlCgformField);
            result.setSuccess(true);
        }
        return result;
    }
}
